package com.sd.app;


import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import com.sd.util.PreferencesManager;
import com.snda.woa.v;


/**
 * 
 * @author Alex.Lu
 *
 */
public class BetaReadApp extends Application{

	/**
	 * 全局数据
	 */
	private AppData mAppData;
    
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		PreferencesManager.getInstance().initPreferences(getApplicationContext());
		
		initData();
		
	}
	
	
	/**
	 * 初始化数据
	 */
	private void initData(){
		ApplicationInfo appi;
		mAppData = AppData.getInstance();
		try {
			appi = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
			Bundle bundle = appi.metaData;
			
			Object value = bundle.get(AppData.META_WOA_KEY_APPID);
			mAppData.mWoaKeyAppid = value.toString();
			
			value = bundle.get(AppData.META_WOA_KEY_CHANNELID);
			mAppData.mWoaKeyChannelID = value.toString();
			
			value = bundle.get(AppData.META_CN_CHANNEL);
			mAppData.mCNChannel = value.toString();
			
			value = bundle.get(AppData.META_BOOK_DIR);
			mAppData.mBookDir = value.toString();
			
			value = bundle.get(AppData.META_CLIENT);
			mAppData.mClient = value.toString();
			
			value = bundle.get(AppData.META_CLENTT_VERSION);
			mAppData.mClientVerison = value.toString();
			
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		AppInit.getInstance().init(getApplicationContext(),mAppData.mBookDir);
	}
}
